<template>
  <div class="app" :class="{ 'has-background-black': isDark }">
    <div class="container is-max-desktop py-6 px-4">
      <div v-if="loading">
        <progress class="progress is-small is-info" max="100">60%</progress>
      </div>
      <div v-if="!loading">
        <ListingsList :listings="listings" :isDark="isDark" />
      </div>
      <button
        class="button is-small is-pulled-right my-4"
        @click="toggleDarkMode"
      >{{ darkModeButtonText }}</button>
    </div>
  </div>
</template>
<script>
import { ref, computed } from "vue";
import { useStore } from "vuex";
import ListingsList from "./components/ListingsList";
export default {
  name: "App",
  setup() {
    const store = useStore();
    const isDark = ref(false);

    const darkModeButtonText = computed(() => {
      return isDark.value ? "light mode" : "dark mode";
    });
    const listings = computed(() => store.getters.listings);
    const loading = computed(() => store.getters.loading);
    const toggleDarkMode = () => {
      isDark.value = !isDark.value;
    };
    store.dispatch("getListings");

    return {
      isDark,
      darkModeButtonText,
      listings,
      loading,
      toggleDarkMode
    };
  },
  components: {
    ListingsList
  }
};
</script>

<style>
html,
body {
  background: #f2f6fa;
}

#app {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media screen and (min-width: 769px) {
  html,
  body {
    height: 100%;
  }
}
</style>
